package javaweek9;

import java.util.Scanner;

class IllegalNameException extends Exception{
	public IllegalNameException(String msg){
		super(msg);
	}
}

class IllegalScoreException extends Exception{
	public IllegalScoreException(String msg){
		super(msg);
	}
}

class Student{
	private String name;
	private int score;
	public String getName() {
		return name;
	}
	public void setName(String name) throws IllegalNameException {
		if(name.charAt(0) >= '0'&&name.charAt(0) <= '9') 
			throw new IllegalNameException("the first char of name must not be digit, name="+name);
		this.name = name;
	}
	public int getScore() {
		return score;
	}
	public void setScore(int score) {
		this.score = score;
	}
	@Override
	public String toString() {
		return "Student [name=" + name + ", score=" + score + "]";
	}
	public int addScore(int score) throws IllegalScoreException{
		int addscore = this.getScore() + score;
		if (addscore < 0||addscore > 100)
			throw new IllegalScoreException("score out of range, score=" + addscore);
		this.score = addscore;
		return addscore;
	}
	
}
public class Test04 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String str = sc.next();
			if (str.equals("new")){
				try {
					Student student = new Student();
					String name = sc.next();
					int addscore = sc.nextInt();
					student.setName(name);
					student.addScore(addscore);
					System.out.println(student);
				} catch (IllegalNameException e) {
					System.out.println(e);
					break;
				} catch (IllegalScoreException e){
					System.out.println(e);
					continue;
				}
			}
		}
		sc.close();
		System.out.println("scanner closed");
	}

}
